/**
 * 弹出框
 * @author Canaan
 * @date 2019/8/22 15:50
 */
const install = function (Vue) {
  const _vue = new Vue();

  function closePromise() {
    return new Promise(function (resolve, reject) {
      _vue.$bus.$on('xy_inner_bus_alert_off', (notice) => {
        resolve(notice);
      });
    });
  }

  function simpleAlert(msg) {
    _vue.$bus.$emit('xy_inner_bus_alert_on', {
      id: Math.uuid(),
      message: msg,
      type: 'simple'
    });

    return closePromise();
  }


  Vue.prototype.$alert = param => {

    if (typeof param === 'string') {
      return simpleAlert(param);
    }

    throw "不支持更多操作...";
  };


};

export default install;
